/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pc;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author echoff <echoffmu@gmail.com>
 */
@Entity
@Table(name = "PRODUCT", catalog = "", schema = "EASY")
@NamedQueries({
    @NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p"),
    @NamedQuery(name = "Product.findByPid", query = "SELECT p FROM Product p WHERE p.pid = :pid"),
    @NamedQuery(name = "Product.findByPname", query = "SELECT p FROM Product p WHERE p.pname = :pname"),
    @NamedQuery(name = "Product.findByPprice", query = "SELECT p FROM Product p WHERE p.pprice = :pprice"),
    @NamedQuery(name = "Product.findByPstorage", query = "SELECT p FROM Product p WHERE p.pstorage = :pstorage"),
    @NamedQuery(name = "Product.findByPimg", query = "SELECT p FROM Product p WHERE p.pimg = :pimg"),
    @NamedQuery(name = "Product.findByVid", query = "SELECT p FROM Product p WHERE p.vid = :vid")})
public class Product implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @Basic(optional = false)
    @Column(name = "PID")
    private BigDecimal pid;
    @Column(name = "PNAME")
    private String pname;
    @Column(name = "PPRICE")
    private BigDecimal pprice;
    @Column(name = "PSTORAGE")
    private BigDecimal pstorage;
    @Column(name = "PIMG")
    private String pimg;
    @Column(name = "VID")
    private BigInteger vid;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "pid")
    private List<Color> colorList;

    public Product() {
    }

    public Product(BigDecimal pid) {
        this.pid = pid;
    }

    public BigDecimal getPid() {
        return pid;
    }

    public void setPid(BigDecimal pid) {
        BigDecimal oldPid = this.pid;
        this.pid = pid;
        changeSupport.firePropertyChange("pid", oldPid, pid);
    }

    public String getPname() {
        return pname;
    }

    public void setPname(String pname) {
        String oldPname = this.pname;
        this.pname = pname;
        changeSupport.firePropertyChange("pname", oldPname, pname);
    }

    public BigDecimal getPprice() {
        return pprice;
    }

    public void setPprice(BigDecimal pprice) {
        BigDecimal oldPprice = this.pprice;
        this.pprice = pprice;
        changeSupport.firePropertyChange("pprice", oldPprice, pprice);
    }

    public BigDecimal getPstorage() {
        if (pstorage == null){
            return BigDecimal.ONE;
        }
        return pstorage;
    }

    public void setPstorage(BigDecimal pstorage) {
        BigDecimal oldPstorage = this.pstorage;
        this.pstorage = pstorage;
        changeSupport.firePropertyChange("pstorage", oldPstorage, pstorage);
    }

    public String getPimg() {
        return pimg;
    }

    public void setPimg(String pimg) {
        String oldPimg = this.pimg;
        this.pimg = pimg;
        changeSupport.firePropertyChange("pimg", oldPimg, pimg);
    }

    public BigInteger getVid() {
        return vid;
    }

    public void setVid(BigInteger vid) {
        BigInteger oldVid = this.vid;
        this.vid = vid;
        changeSupport.firePropertyChange("vid", oldVid, vid);
    }

    public List<Color> getColorList() {
        return colorList;
    }

    public void setColorList(List<Color> colorList) {
        this.colorList = colorList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (pid != null ? pid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product)) {
            return false;
        }
        Product other = (Product) object;
        if ((this.pid == null && other.pid != null) || (this.pid != null && !this.pid.equals(other.pid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pc.Product[ pid=" + pid + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
